package com.hainatong.jcmvvmbase;


import android.content.Context;
import android.content.Intent;
import android.util.Log;
import androidx.fragment.app.Fragment;
import androidx.viewpager2.widget.ViewPager2;
import com.hainatong.jcmvvmbase.databinding.ActivitySecondBinding;
import com.hainatong.mvvmbase.base.BaseMvvmActivity;
import com.hainatong.mvvmbase.base.NoViewModel;

import java.util.ArrayList;
import java.util.List;

public class SecondActivity extends BaseMvvmActivity<ActivitySecondBinding, NoViewModel>
{
    private MyFragmentPagerAdapter pagerAdapter;

    private List<Fragment> fragmentList;

    public static void start(Context context)
    {
        Intent start = new Intent(context ,SecondActivity.class);
        context.startActivity( start );
    }

    @Override
    protected int getLayoutId()
    {
        return R.layout.activity_second;
    }

    @Override
    protected void initView()
    {
        fragmentList = new ArrayList<>();
        pagerAdapter = new  MyFragmentPagerAdapter(this,fragmentList);
        viewDataBinding.vp2.setAdapter( pagerAdapter );

        viewDataBinding.vp2.registerOnPageChangeCallback(new ViewPager2.OnPageChangeCallback() {
            @Override
            public void onPageSelected(int position)
            {
                super.onPageSelected(position);
                Log.e("vp2" , "position = "+position);
            }
        });
    }

    @Override
    protected void initData()
    {

        fragmentList.add( FirstFragment.newInstance() );
        fragmentList.add( LazyFragment.newInstance() );
        pagerAdapter.notifyDataSetChanged();

    }

    @Override
    protected int getBindingVariable()
    {
        return 0;
    }



    @Override
    protected void onRetryBtnClick() {

    }
}
